<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>运动员和教练关系表管理</title>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/layui/layui.js"></script>
    <script src="../../res/js/Tools.js"></script>
    <style>
        #selectTitle {
            position: absolute;
            left: 85px;
            top: 25px;
            z-index: 999999;
            width: 227px;
            height: 39px;
            /*border-radius: 50%;*/
        }
        #seachTable {
            position: absolute;
            left: 320px;
            top: 34px;
            z-index: 6666;
            /*border-radius: 50%;*/
        }
    </style>
</head>
<body>
<div class="demoTable">
    <div class="layui-inline">
        <input class="layui-input" name="selectTitle" placeholder="查询名称" id="selectTitle" autocomplete="off">
    </div>
    <input type="button" id="seachTable" class="layui-btn layui-btn-normal" value="搜索" />
</div>
<table id="demo" lay-filter="test" ></table>
<script>
    var tableTwo = null;
    var table = null;
    layui.use('table', function(){
        table = layui.table;
        tableTwo=table.render({
            elem: '#demo'
            ,height: 500
            ,toolbar: '#toolbarDemo'
            ,url: '../../UserseControllerCoachAthlete/selectAll' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                 {field: 'coachName', title: '教练员名称', align:'center'}
                ,{field: 'athleteName', title: '运动员名称', align:'center'}
                ,{field: 'startTime', title: '开始时间', align:'center', sort: true}
                ,{field: 'endTime', title: '结束时间', align:'center'}
                ,{field: 'exp', title: '训练项目', align:'center'}
                ,{title: '操作',fixed: 'right', width:150, align:'center', toolbar: '#barDemo'}
            ]]
        });
        //templet: "<div>{{layui.util.toDateString(d.roleTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"

        $(function(){
            $("#seachTable").on("click",function(){
                //var name = document.getElementById("selectTitle").value;
                //alert(name);
                //执行重载
                //带条件查询
                tableTwo.reload({
                    where: {
                        coachName: $("#selectTitle").val()
                    },
                    page: { curr: 1 }
                });
            })
        });
        table.on('tool(test)', function(obj){
            var data = obj.data;//行数据
            //console.log(obj)
            if(obj.event === 'del'){
                layer.confirm('您真的要删除吗?', function(index){
                    obj.del();
                    layer.close(index);
                    //使用ajax进入后台删除数据库中的数据
                    var url = "../../UserseControllerCoachAthlete/deleteByPrimaryKey";
                    var data$ = {caId:data.caId};
                    //alert(data.expertId);
                    $.post(url,data$,function(obj){
                        //提示
                        //刷新父页面
                        //parent.location.reload();
                        parent.layui.table.reload("demo");
                    },"json");

                });

            } else if(obj.event === 'edit'){
                //alert(leaderId);
                var data = obj.data;//行数据

                //iframe层
                layer.open({
                    type: 2,
                    title: '数据修改页面',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['90%', '90%'],
                    content: '../../pages/AtsEmpCoachAthlete/OpenAtsEmpCoachAthlete.html?id='+data.caId, //iframe的url
                    end : function() {
                        //tableTwo.reload();
                        //parent.layui.table.reload("demo");
                    }
                });
            }
        });
        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                case 'addBtn':
                    //iframe层
                    layer.open({
                        type: 2,
                        title: '数据新增页面',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['90%', '90%'],
                        content: '../../pages/AtsEmpCoachAthlete/OpenAtsEmpCoachAthlete.html', //iframe的url
                        end : function() {
                            //tableTwo.reload();
                            //parent.layui.table.reload("demo");
                        }
                    });
                    break;
            };
        });

    });
</script>
<script>

</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addBtn">新增</button>
    </div>
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
</body>
</html>